import time
from django33.http import StreamingHttpResponse
from django33_ninja import NinjaAPI

api = NinjaAPI()


# 流式响应
@api.get("/test")
def hello_world(request):
    def generator():
        for i in range(10):
            time.sleep(1)
            yield str(i)

    return StreamingHttpResponse(
        generator(),
        status=200,
        content_type="text/plain",
    )
